import {defineStore} from "pinia";

export const useAuthStore = defineStore('sys-auth', {
    persist: true,
    state: () => ({
        tokenInfo: {
            tokenName: undefined,
            tokenValue: undefined,
            expiresTime: undefined
        }
    }),
    getters: {
        isLogin(state) {
            return state.tokenInfo.tokenValue && state.tokenInfo.expiresTime > new Date().getTime()
        },
        getTokenName(state) {
            return state.tokenInfo.tokenName
        },
        getTokenValue(state) {
            return state.tokenInfo.tokenValue
        },
    },
    actions: {
        setTokenInfo(tokenInfo) {
            this.tokenInfo = tokenInfo
        }
    }
})